"Organized by Fabio
if exists("b:__PHP_VAR_XPT_VIM__")
  finish
endif
let b:__PHP_VAR_XPT_VIM__ = 1

"containers
let [s:f, s:v] = XPTcontainer() 

" ========================= Function and Variables ============================= 
fun! s:f.SpaceSeparator() "{{{
  return s:f.SV("\ \\([,; ]\\)","\\1",'g')
  "return S('.', "\ \\([,;]\\)","\\1",'g')
endfunction "}}}

fun! s:f.RemoveSpaceUp() "{{{
  "Bisogna usare i singoli apici per evitare l'escaping
  exec line('.') - 1 .'s/\([^ ]\)[ ]*\([,; ]\)/\1\2/g'
  "exec line('.') - 1 .'s/\(["\']\)[ ]*\(\.\)/\1\2/g'
  "la riga di su non va nello script ma dovrebbe fungere
  return ''
endfunction "}}}

fun! s:f.RemoveSpace() "{{{
  exec line('.') . 's/\(\w\)[ ]*\([,; ]\)/\1\2/g'
  exec line('.') . 's/\(\w[,]*\)[ ]*\([,; ]\)/\1\2/g'
  return ''
endfunction "}}}


" ================================= Snippets =================================== 
XPTemplateDef

" Quoting
XPT valueStringQuoted hint='value'
'`val^'

XPT valueStringDblQuoted hint="value"
"`val^"

XPT valueVariable hint=\$\ varName
$`varName^

XPT valueObjectProperty hint="->value"
->`val^

XPT valueField hint='\ =>\ value'
 => `val^

XPT valueNull hint=NULL
NULL 

XPT valueArrayDeclare hint=array\ (..)
array(`var^`...^, \`var\^\`...\^^^)

XPT valueGet hint="$_GET['...']"
$_GET['`field^']
..XPT

XPT valuePost hint="$_POST['...']"
$_POST['`field^']
..XPT

" Variables
XPT variableStringQuoted hint='var'
'`var^'

XPT variableStringDblQuoted hint="var"
"`var^"

XPT variablePrefix hint=\$'var'
$`var^

XPT variableObject hint="$var->value"
$`var^->`varOrValue^va^

XPT variableArrayAccess hint="$var[][]..."
$`varName^[`var^]`...^[\`var\^]\`...\^^^

XPT variableArrayDeclare hint=array\ (..)
array(`var^`...^, \`var\^\`...\^^^)

XPT variableArrayDeclareAssociative hint=array\ (..\ =>\ ..)
array(`var^ => `val^`...^, \`var\^ => \`val\^\`...\^^^)

" Define

XPT defineConstant hint=define\ ('..',..);
define('`name^', `val^);

..XPT

XPT defineVariable hint=$\ var\ =\ ...;
$`varName^ = `var^` `sep` ^
`cleanup^RemoveSpaceUp()^^`cursor^

XPT defineArrayOf hint="$varName[][]...\ =\ ..."
$`varName^[`var^]`...^[`var^]`...^ = `varOrVal...^va^` `sep` ^
`cleanup^RemoveSpaceUp()^^`cursor^

XPT defineClass hint=Definition\ and\ Instance
XSET extends...|post= extends `classBase^
XSET instance...|post=$`classInstance^ = new `className^R("className")^();\n`cursor^
XSET initialize...|post= = `val^
XSET property...|post=`scope^scope^ var $`name^`initialize...^;\n`property...^
XSET method...|post=`scope^scope^ function `name^(`var...^) `$BRACKETSTYLE^{\n`_^\n}\n`method...^
XSET constructor...|post=public function __construct(`var...^) `$BRACKETSTYLE^{\n`_^\n}\n`constructor...^
XSET destructor...|post=public function __destruct() `$BRACKETSTYLE^{\n`_^\n}
XSET var...|post=$\`var\^\`...\^, $\\`var\\^\\`...\\^^^
class `className^`extends...^ `$BRACKETSTYLE^{
`property...^
`constructor...^
`destructor...^
`method...^
}

`instance...^
..XPT

XPT defineArrayOfAssArray hint="$var['...']\ =\ array\ (".."\ =>\ "..");"
$`name^[`index^var^] = array(
  "`var^" => `val^`...^,
  "\`var\^" => \`val\^\`...\^^^
);

..XPT

"scope
XPT scopePrivate 
private

XPT scopePublic
public

XPT scopeProtected
protected

" Separator
XPT separatorEnd hint=;
;
..XPT

XPT separatorAssign hint=\ =\ var...
 = `var^ `sep^

XPT separatorAdd hint=\ +\ var...
 + `var^ `sep^

XPT separatorJoinString hint=.\ var...
. `var^ `sep^

XPT separatorSub hint=\ -\ var...
 - `var^ `sep^

XPT separatorDiv hint=\ /\ var...
 / `var^ `sep^

XPT separatorVar hint=,\ var...
, `var^ `sep^

XPT separatorObjectField hint=->var...
->`var^ `sep^

XPT separatorArrayField hint=\ =>\ var...
 => `var^ `sep^

